package com.sxbang.friday.dao;

import com.sxbang.friday.model.SysUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserDao {



    @Select("select * from sys_user t where t.username = #{username}")
    SysUser getUser(String username);


    @Select("select count(*) from sys_user")
    Long countAllUsers();//返回数据行数

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into sys_user(username,password,nickname,headImgUrl,phone,telephone,email,birthday,sex,status,createTime,updateTime) values(#{username},#{password},#{nickname},#{headImgUrl},#{phone},#{telephone},#{email},#{birthday},#{sex},#{status},#{createTime},#{updateTime})")
    int save(SysUser sysUser);

    @Select("select * from sys_user t where t.telephone = #{telephone}")
    SysUser getUserByPhone(String telephone);

    @Select("select * from sys_user t where t.id = #{id}")
    SysUser getUserById(Long id);

    int updateUser(SysUser sysUser);

    @Delete("delete from sys_user where id = #{id}")
    int deleteUser(int id);

    @Select("select count(*) from sys_user t where t.username like '%${username}%'")
    Long getUserByFuzzyUsername(@Param("username") String username);

    @Select("select * from sys_user t order by t.id limit #{startPosition},#{limit}")
    //limit开始的起始行数（从0开始），显示行数
    List<SysUser> selectUser(@Param("startPosition") Integer startPosition, @Param("limit") Integer limit);//@Param传入参数

    @Select("select * from sys_user t where t.username like '%${username}%' limit #{startPosition},#{limit}")
    List<SysUser> getUserByFuzzyUsernameByPage(@Param("username")String username, @Param("startPosition")Integer startPosition,@Param("limit") Integer limit);
}
